<template>
  <div class="content">
    <div class="w_img">
      <img :src="datamsg.pic" alt="">
    </div>
    <div class="w_title">{{datamsg.name}}</div>
    <div class="w_time">{{datamsg.use_end_time}}</div>
    <div class="writebox" v-if="datamsg.state === 0" @click="show = true">确认核销</div>
    <div class="writebox qux" v-else-if="datamsg.state === 1">已使用</div>
    <div class="writebox qux" v-else>已过期</div>
    <!-- 弹出层 -->
    <van-popup class="write_popup" v-model="show">
      <div class="write_box">
        <div class="wb_title">核销确认</div>
        <div class="wb_cont">你是否确认核销订单</div>
        <div class="btn_box">
           <div class="btnsty qux" @click="show = false">取消</div>
           <div class="btnsty quer" @click="surebtn">确认</div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import { useInfo, confirmUse } from '@/api/public'
export default {
  name: 'Write',
  data () {
    return {
      show: false,
      aid: '',
      uid: '',
      noceStr: '',
      singstr: '',
      datamsg: {}
    }
  },
  created () {
    if (this.$route.query.aid) {
      this.aid = this.$route.query.aid
      this.uid = this.$route.query.uid
      this.noceStr = this.$route.query.noceStr
      this.singstr = this.$route.query.singstr
    }
    this.getdata()
  },
  methods: {
    getdata () {
      const { aid, uid, noceStr, singstr } = this
      useInfo(aid, uid, noceStr, singstr).then(res => {
        this.datamsg = res
      }).finally(() => {
      })
    },
    surebtn () {
      const { aid, uid, noceStr, singstr } = this
      confirmUse(aid, uid, noceStr, singstr).then(res => {
        this.show = false
        this.$toast.success('核销成功')
      }).finally(() => {
      })
    }
  }
}
</script>

<style scoped lang="less">
.content{
  width: 100%;
  height: 100%;
  padding: 19% 0;
  background-color: white;
  box-sizing: border-box;
  text-align: center;
  .w_img{
    margin: 0 auto;
    width: 200px;
    height: 200px;
    overflow: hidden;
    background-color: #ffffff;
    border-radius: 50%;
    box-shadow: -1px 5px 15px 1px rgba(232, 232, 232, 0.5);
    img{
        width: 100%;
        height: 100%;
        background-size: cover;
    }
  }
  .w_title{
    margin: 30px 0;
    text-align: center;
    font-size: 36px;
  }
  .w_time{
    font-size: 28px;
    color: #666666;
  }
  .writebox{
    margin: 100px auto 0;
    width: 400px;
    height: 80px;
    background: #ff3c3b;
    border-radius: 40px;
    line-height: 80px;
    line-height: 80px;
    color: #ffffff;
    font-size: 28px;
    text-align: center;
  }
  .qux{
    background-color: #d7d7d7;
  }
  .write_popup{
    width: 550px;
    height: 349px;
    border-radius: 20px;
    .write_box{
      padding: 40px 20px;
      background-color: white;
      box-sizing: border-box;
      text-align: center;
      .wb_title{
        font-size: 36px;
      }
      .wb_cont{
        margin: 50px 0;
        font-size: 28px;
        color: #666666;
      }
      .btn_box{
        display: flex;
        align-items: center;
        justify-content: space-between;
        .btnsty{
          width: 250px;
          height: 80px;
          line-height: 80px;
          text-align: center;
          border-radius: 40px;
          font-size: 28px;
          color: white;
        }
        .qux{
          background-color: #d7d7d7;
        }
        .quer{
          background: #fca64a;
        }
      }
    }
  }
}
</style>
